const { clone } = require('./downloadTemplate.js')
const { ask } = require('./ask.js');
const generate = require('./generate')
const path = require('path');
const preCheck = require('./preCheck')

module.exports.init = async name => {
    try {
        // 前置校验
        await preCheck(name)

        //询问模块
        const askData = await ask();

        // 下载模版
        // const downData  = await clone('direct:https://gitee.com/hejialianghe/xxx', name)
        const downData = { tempName: `${__dirname}/../framework` };

        // 渲染模板
        await generate({
            ...askData,
            ...downData,
            projectName: name,
            projectRoot: path.resolve(process.cwd(), name),
            name: name,
        })
    } catch (err) {
        console.log(err)

    }
}
